/*
 * @(#)WorkflowProgressAttachment.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
import com.dcivision.workflow.bean.WorkflowProgressAttachment;

/**
 * WorkflowProgressAttachmentDAObject.java
 *
 * This class is the data access bean for table "WORKFLOW_PROGRESS_ATTACHMENT".
 *
 * @author Angus Shiu
 * @company DCIVision Limited
 * @creation date 02/12/2003
 * @version $Revision: 1.13 $
 */

public class WorkflowProgressAttachmentDAObject extends AbstractDAObject {
  
  public static final String REVISION = "$Revision: 1.13 $";
  
  public static final String TABLE_NAME = "WORKFLOW_PROGRESS_ATTACHMENT";
  
  public WorkflowProgressAttachmentDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }
  
  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("MTM_WF_PROGRESS_USER_RECORD_ID");
    this.vecDBColumn.add("ATTACHMENT_NAME");
    this.vecDBColumn.add("ATTACHMENT_TYPE");
    this.vecDBColumn.add("EXTERNAL_ID");
    this.vecDBColumn.add("CONTENT_SIZE");
    this.vecDBColumn.add("FLOW_TYPE");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }
  
  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          return(tmpWorkflowProgressAttachment);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        
        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }
        
        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());
        
        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }
        
        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString());
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
        
        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();
        
        this.positionCursor(rs, startOffset, pageSize);
        
        while (rs.next() && rowLoopCnt<pageSize) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          tmpWorkflowProgressAttachment.setRecordCount(totalNumOfRecord);
          tmpWorkflowProgressAttachment.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }
  
  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }
  
  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowProgressAttachment tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)obj;
    //WorkflowProgressAttachment tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)((WorkflowProgressAttachment)obj).clone();
    
    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   WORKFLOW_PROGRESS_ATTACHMENT(ID, MTM_WF_PROGRESS_USER_RECORD_ID, ATTACHMENT_NAME, ATTACHMENT_TYPE, EXTERNAL_ID, CONTENT_SIZE, FLOW_TYPE, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpWorkflowProgressAttachment.getMtmWorkflowProgressUserRecordID());
        setPrepareStatement(preStat, 3, tmpWorkflowProgressAttachment.getAttachmentName());
        setPrepareStatement(preStat, 4, tmpWorkflowProgressAttachment.getAttachmentType());
        setPrepareStatement(preStat, 5, tmpWorkflowProgressAttachment.getExternalID());
        setPrepareStatement(preStat, 6, tmpWorkflowProgressAttachment.getContentSize());
        setPrepareStatement(preStat, 7, tmpWorkflowProgressAttachment.getFlowType());
        setPrepareStatement(preStat, 8, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 9, new Integer(0));
        setPrepareStatement(preStat, 10, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 11, currTime);
        setPrepareStatement(preStat, 12, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 13, currTime);
        preStat.executeUpdate();
        tmpWorkflowProgressAttachment.setID(nextID);
        tmpWorkflowProgressAttachment.setCreatorID(sessionContainer.getUserRecordID());
        tmpWorkflowProgressAttachment.setCreateDate(currTime);
        tmpWorkflowProgressAttachment.setUpdaterID(sessionContainer.getUserRecordID());
        tmpWorkflowProgressAttachment.setUpdateDate(currTime);
        tmpWorkflowProgressAttachment.setUpdateCount(new Integer(0));
        tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
        tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
        return(tmpWorkflowProgressAttachment);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowProgressAttachment tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)((WorkflowProgressAttachment)obj).clone();
    
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE WORKFLOW_PROGRESS_ATTACHMENT ");
        sqlStat.append("SET  MTM_WF_PROGRESS_USER_RECORD_ID=?, ATTACHMENT_NAME=?, ATTACHMENT_TYPE=?, EXTERNAL_ID=?, CONTENT_SIZE=?, FLOW_TYPE=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpWorkflowProgressAttachment.getMtmWorkflowProgressUserRecordID());
        setPrepareStatement(preStat, 2, tmpWorkflowProgressAttachment.getAttachmentName());
        setPrepareStatement(preStat, 3, tmpWorkflowProgressAttachment.getAttachmentType());
        setPrepareStatement(preStat, 4, tmpWorkflowProgressAttachment.getExternalID());
        setPrepareStatement(preStat, 5, tmpWorkflowProgressAttachment.getContentSize());
        setPrepareStatement(preStat, 6, tmpWorkflowProgressAttachment.getFlowType());
        setPrepareStatement(preStat, 7, new Integer(tmpWorkflowProgressAttachment.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 8, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 9, currTime);
        setPrepareStatement(preStat, 10, tmpWorkflowProgressAttachment.getID());
        setPrepareStatement(preStat, 11, tmpWorkflowProgressAttachment.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpWorkflowProgressAttachment.setUpdaterID(sessionContainer.getUserRecordID());
          tmpWorkflowProgressAttachment.setUpdateDate(currTime);
          tmpWorkflowProgressAttachment.setUpdateCount(new Integer(tmpWorkflowProgressAttachment.getUpdateCount().intValue() + 1));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          return(tmpWorkflowProgressAttachment);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    WorkflowProgressAttachment tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)((WorkflowProgressAttachment)obj).clone();
    
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpWorkflowProgressAttachment.getID());
        setPrepareStatement(preStat, 2, tmpWorkflowProgressAttachment.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpWorkflowProgressAttachment);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    WorkflowProgressAttachment tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)this.oldValue;
    
    if (tmpWorkflowProgressAttachment != null) {
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getMtmWorkflowProgressUserRecordID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getAttachmentName()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getAttachmentType()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getExternalID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getContentSize()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getFlowType()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdateDate()));
    }
    
    tmpWorkflowProgressAttachment = (WorkflowProgressAttachment)obj;
    if (tmpWorkflowProgressAttachment != null) {
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getID()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getMtmWorkflowProgressUserRecordID()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getAttachmentName()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getAttachmentType()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getExternalID()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getContentSize()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getFlowType()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpWorkflowProgressAttachment.getUpdateDate()));
    }
    
    auditTrailBase(opMode, oldValues, newValues);
  }
  
  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  
  /**
   * Gets a list of workflow attachments by workflow progress ID.
   *
   * @param progressID The workflow progress ID
   * @return List of workflow progress attachment
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgressAttachment
   */
  public List getListByWorkflowProgressID(Integer workflowProgressID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A, MTM_WF_PROGRESS_USER_RECORD B ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.MTM_WF_PROGRESS_USER_RECORD_ID = B.ID AND B.WORKFLOW_PROGRESS_ID = ?");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, workflowProgressID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of workflow attachments that is uploaded by the specified progress user record
   * 
   * @param mtmWorkflowProgressUserRecordID The progress user record ID (NOT user record ID)
   * @return List of workflow progress attachment
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   * @see com.dcivision.workflow.bean.WorkflowProgressAttachment
   */
  public List getListByMtmWorkflowProgressUserRecordID(Integer mtmWorkflowProgressUserRecordID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A ");
        sqlStat.append("WHERE  A.MTM_WF_PROGRESS_USER_RECORD_ID = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        this.setPrepareStatement(preStat, 1, mtmWorkflowProgressUserRecordID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Gets a list of workflow progress attachments of the given workflow track and of
   * the given type
   * 
   * @param trackID The workflow track ID
   * @param attachmentType The attachment type
   * @return List of workflow progress attachment
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgressAttachment
   * @deprecated
   */
  public List getListByTrackIDAndAttachmentType(Integer trackID, String attachmentType) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A, MTM_WF_PROGRESS_USER_RECORD B, WORKFLOW_PROGRESS C ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.MTM_WF_PROGRESS_USER_RECORD_ID = B.ID AND B.WORKFLOW_PROGRESS_ID = C.ID ");
        sqlStat.append("       AND A.ATTACHMENT_TYPE = ? AND C.TRACK_ID = ? ");
        sqlStat.append("ORDER BY A.ID DESC ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, attachmentType);
        this.setPrepareStatement(preStat, 3, trackID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  /**
   * Deletes the progress attachment that are uploaded by the specified progress user
   * record ID(s)
   * 
   * @param mtmWorkflowRpogressUserRecordIDAry Comma separated progress user record ID
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.MtmWorkflowProgressUserRecord
   */
  public synchronized void deleteByMtmWorkflowRpogressUserRecordID(String mtmWorkflowRpogressUserRecordIDAry) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT ");
        sqlStat.append("WHERE  MTM_WF_PROGRESS_USER_RECORD_ID IN (  "+mtmWorkflowRpogressUserRecordIDAry+"  ) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          //throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        }
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Gets a list of workflow progress attachments of the given workflow track
   * 
   * @param trackID The workflow track ID
   * @return List of workflow progress attachment
   * @throws ApplicationException
   * @see com.dcivision.workflow.bean.WorkflowProgressAttachment
   */
  public List getListByTrackID(Integer trackID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.MTM_WF_PROGRESS_USER_RECORD_ID, A.ATTACHMENT_NAME, A.ATTACHMENT_TYPE, A.EXTERNAL_ID, A.CONTENT_SIZE, A.FLOW_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   WORKFLOW_PROGRESS_ATTACHMENT A, MTM_WF_PROGRESS_USER_RECORD B, WORKFLOW_PROGRESS C ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? AND A.MTM_WF_PROGRESS_USER_RECORD_ID = B.ID AND C.TRACK_ID = ? ");
        sqlStat.append("AND B.WORKFLOW_PROGRESS_ID = C.ID AND A.RECORD_STATUS = B.RECORD_STATUS AND A.RECORD_STATUS = C.RECORD_STATUS ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, trackID);
        rs = preStat.executeQuery();
        while (rs.next()) {
          WorkflowProgressAttachment tmpWorkflowProgressAttachment = new WorkflowProgressAttachment();
          tmpWorkflowProgressAttachment.setID(getResultSetInteger(rs, "ID"));
          tmpWorkflowProgressAttachment.setMtmWorkflowProgressUserRecordID(getResultSetInteger(rs, "MTM_WF_PROGRESS_USER_RECORD_ID"));
          tmpWorkflowProgressAttachment.setAttachmentName(getResultSetString(rs, "ATTACHMENT_NAME"));
          tmpWorkflowProgressAttachment.setAttachmentType(getResultSetString(rs, "ATTACHMENT_TYPE"));
          tmpWorkflowProgressAttachment.setExternalID(getResultSetString(rs, "EXTERNAL_ID"));
          tmpWorkflowProgressAttachment.setContentSize(getResultSetInteger(rs, "CONTENT_SIZE"));
          tmpWorkflowProgressAttachment.setFlowType(getResultSetString(rs, "FLOW_TYPE"));
          tmpWorkflowProgressAttachment.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpWorkflowProgressAttachment.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpWorkflowProgressAttachment.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpWorkflowProgressAttachment.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpWorkflowProgressAttachment.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpWorkflowProgressAttachment.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpWorkflowProgressAttachment.setCreatorName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getCreatorID()));
          tmpWorkflowProgressAttachment.setUpdaterName(UserInfoFactory.getUserFullName(tmpWorkflowProgressAttachment.getUpdaterID()));
          result.add(tmpWorkflowProgressAttachment);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  
}
